<template>
	<!-- 社区任务 -->
	<view class="CommunityInspection-container">
		<view class="commun-content">
			<view class="commun-item" v-for="(item,index) in commuList" :key="index" @click="handleGoInfo(item.id)">
				<view class="item-head">
					<view class="head-left">{{ item.title }}</view>
					<view class="head-right">{{ item.completeness }}%</view>
				</view>
				<view class="item-mid">
					<view class="mid-left">{{ item.gridName }}</view>
					<view class="mid-right">{{ item.taskStatus_dictText }}</view>
				</view>
				<view class="item-bottom">计划巡查时间:{{ item.startDate }} - {{ item.endDate }}</view>
			</view>
		</view>
		<u-loadmore :status="status" icon-color="#007AFF" />
	</view>
</template>

<script>
		export default {
			data() {
				return {
					commuList:[],
					taskType:2,// 2巡查 3走访
					pageNo:1,
					pageSize:10,
					status: 'loading',
					tolnum:0,
				}
			},
			mounted() {
				this.getMyTask()
			},
			// 上拉
			onReachBottom() {
				this.pageNo = this.pageNo + 1
				if(this.pageNo > this.tolnum) {
					return this.status = 'nomore'
				}
				this.getMyTask()
			},
			// 下拉
			onPullDownRefresh() {
				this.commuList=[]
				this.pageNo = 1
				this.status = 'loading'
				this.getMyTask()
				setTimeout(function () {
				    uni.stopPullDownRefresh();
				}, 1500);
			},
			methods: {
				getMyTask() {
					let params = {
						taskType:this.taskType,
						pageNo:this.pageNo,
						pageSize:this.pageSize
					}
					console.log(params)
					this.$u.api.myTask(params)
						.then(res => {
							console.log(res)
							if(res.code == 200) {
								this.tolnum = res.result.pages
								if (res.result.pages == 0) {
									this.status = 'nomore'
								}
								
								this.commuList = res.result.records
								
								if(this.pageNo == 1) {
									if(this.pageNo == this.tolnum) {
										this.status = 'nomore'
									}
								}
							}
						})
						.catch(err => {
							console.log(err)
							this.status = 'nomore'
							uni.showToast({
								title:'获取任务失败',
								icon:'none'
							})
						})
				},
				handleGoInfo(id) {
					uni.navigateTo({
						url:'../TaskInfo/TaskInfo?id='+id
					})
				}
			}
		}
</script>

<style lang="scss" scoped>
	.CommunityInspection-container{
		background-color: #f5f6f7;
		min-height: 100vh;
		.head{
			width: 100%;
			height: 90rpx;
			position: fixed;
			top: 0;
			left: 0;
		}
		.commun-content{
			padding: 20rpx;
			.commun-item{
				background-color: #fff;
				padding: 20rpx;
				height: 160rpx;
				width: 100%;
				border-radius: 10rpx;
				box-shadow: 3px 3px 3px #eee;
				display: flex;
				justify-content: space-around;
				align-items: flex-start;
				flex-direction: column;
				margin-bottom: 20rpx;
				.item-head{
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 100%;
					.head-left{
						color: #000;
						font-size: 30rpx;
						font-weight: 600;
					}
					.head-right{
						color: #007AFF;
						font-size: 25rpx;
					}
				}
				.item-mid{
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 100%;
					.mid-left{
						color: #333;
						font-size: 26rpx;
					}
					.mid-right{
						color: #F0AD4E;
						font-size: 25rpx;
					}
				}
				.item-bottom{
					color: #999;
					font-size: 24rpx;
				}
			}
		}
	}
</style>
